﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ExORMDesginer.Models;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Document;
using ExORMDesginer.Plugin;

namespace ExORMDesginer.UserControls.CCodeEditer
{


    /// <summary>
    /// Implements AvalonEdit ICompletionData interface to provide the entries in the completion drop down.
    /// </summary>
    public class TableCompletionData : ICompletionData
    {
        public TableCompletionData(DbEntity entity)
        {
            _entity = entity;
            this.Text = _entity.Name;
            _entity.Memo = "表名：" + _entity.Name;
        }

        public System.Windows.Media.ImageSource Image
        {
            get { return null; }
        }

        private DbEntity _entity;

        public string Text { get; private set; }

        // Use this property if you want to show a fancy UIElement in the drop down list.
        public object Content
        {
            get
            {
                var view = new TableCompletionDataTemplate();
                view.DataContext = _entity;
                return view;
            }
        }

        public object Description
        {
            get
            {
                var view = new TableCompletionDataTemplate();
                view.DataContext = _entity;
                return view;
            }
        }

        public double Priority { get { return 0; } }

        public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            textArea.Document.Replace(completionSegment, _entity.Name);
        }

    }
}